package cn.itcast.fk;

import cn.itcast.base.BaseController;
import cn.itcast.domain.User;
import cn.itcast.domain.feedback.Feedback;
import cn.itcast.service.feedback.FeedbackService;
import org.apache.poi.ss.formula.functions.Odd;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping(value = "/user/oldread")
public class OldFeedBackController extends BaseController {
    @Autowired
    private FeedbackService feedbackService;

    @RequestMapping(value ="/list",name = "用户已读的邮件")
    public String list(){
        List<Feedback> list=null;
        Feedback feedback = new Feedback();
        feedback.setCompany_id(company_id);
        feedback.setStat(1);//未读
        User user = (User)session.getAttribute("loginUser");
        if (user.getDegree()==0){//sass
            feedback.setRadio("1");//sass可看
            list= feedbackService.showSass(feedback);
        }else{
            feedback.setRadio("2");//企业
            list= feedbackService.showlist(feedback);
        }
        session.setAttribute("user",user);
        session.setAttribute("olddata",list);
        System.out.println(list);
         return "fankui/oldread";
    }
    @RequestMapping(value = "/oldlist",name = "显示")
    public String oldlist(){
        List<Feedback> list=null;
        Feedback feedback = new Feedback();
        feedback.setCompany_id(company_id);
        feedback.setStat(1);//未读
        if (user.getDegree()==0){
            feedback.setRadio("2");//sass可看
            list= feedbackService.showSass(feedback);
        }else{
            feedback.setRadio("1");//sass可看
            list= feedbackService.showlist(feedback);
        }
        session.setAttribute("olddata",list);
        return "fankui/oldread";
    }
    @RequestMapping(value = "/delete.do",name = "删除已经查看的邮件")
    public String delete(String[] id){
        System.out.println(id);
        feedbackService.delete(id);
        return "redirect:/user/oldread/list.do";
    }
    @RequestMapping(value = "/toView",name ="展示")
    public String toView(String id){
        Feedback byFeed = feedbackService.findByFeed(id);
        request.setAttribute("feedback",byFeed);
        return "fankui/read-mail";
    }
}
